import configparser

config = configparser.ConfigParser()
config.read('config.ini')

def getAPIKey():
    return config['api']['apikey']
def getSecretKey():
    return config['api']['secretkey']

def getPassPhrase():
    return config['api']['passphrase']
def getFlag():
    return config['api']['flag']
def getWaitingSell():
    if 'ownCount' in config['trade'] and is_float(config['trade']['ownCount']):
        value = config['trade']['waitingSell']
        return value.lower() == "true"
    else:
        return False

def getOwnCount():
    return float(config['trade']['ownCount'])


def updateConfig():
    # 写入到文件
    with open('config.ini', 'w') as configfile:
        config.write(configfile)

def updateOwnCount(value):
    config['trade']['ownCount'] = value
    updateConfig()

def updateWaitingSell(value):
    config['trade']['waitingSell'] = value
    updateConfig()


def is_float(value):
    try:
        float(value)
        return True
    except ValueError:
        return False